package com.colourclash.fruitopia.models 
{
	import com.colourclash.fruitopia.controllers.FruitopiaGameController;
	import com.colourclash.fruitopia.enums.FruitType;
	import com.colourclash.fruitopia.events.PropertyChangeEvent;
	import com.colourclash.fruitopia.utils.BaseModel;
	import flash.display.Sprite;
	/**
	 * Main game model
	 * informs the view via propertyChanged(property)
	 * 
	 * @author Patrick Hammond
	 */
	public class FruitopiaGameModel extends BaseModel
	{

		private var _fruits:Array;
		public function get fruits():Array 
		{
			return _fruits;
		}
		public function set fruits(value:Array):void 
		{
			_fruits = value;
		}

		private var _firstSelectedFruit:FruitModel;
		public function get firstSelectedFruit():FruitModel 
		{
			return _firstSelectedFruit;
		}
		public function set firstSelectedFruit(value:FruitModel):void 
		{
			_firstSelectedFruit = value;
		}
		
		private var _secondSelectedFruit:FruitModel;
		public function get secondSelectedFruit():FruitModel 
		{
			return _secondSelectedFruit;
		}
		public function set secondSelectedFruit(value:FruitModel):void 
		{
			_secondSelectedFruit = value;
		}

		private var _numberOfFruits:int;
		public function get numberOfFruits():int 
		{
			return _numberOfFruits;
		}
		public function set numberOfFruits(value:int):void 
		{
			_numberOfFruits = value;
		}

		private var _score:int;
		public function get score():int 
		{
			return _score;
		}
		public function set score(value:int):void 
		{
			_score = value;
			propertyChanged("score");
		}
		
		public function FruitopiaGameModel() 
		{
			_score = 0;
			
			_numberOfFruits = 4;
			
			_fruits = 	[
							[0, 0, 0, 0, 0],
							[0, 0, 0, 0, 0],
							[0, 0, 0, 0, 0],
							[0, 0, 0, 0, 0],
							[0, 0, 0, 0, 0]
						];
		}
		
		public function createFruits():void 
		{
			for (var i:int = 0; i < 5; i++) 
			{
				for (var j:int = 0; j < 5; j++) 
				{
					var fruitType:int = int(Math.random() * 7);
					_fruits[i][j] = new FruitModel(FruitType.getTypeByIndex(fruitType), i, j);
				}
			}
			
			updateFruits();
		}
		
		public function updateFruits():void 
		{
			propertyChanged("fruits");
		}
		

		
	}

}